package com.chendechao.a2207a_ivideo

import android.app.Application
import android.content.ContentValues.TAG
import android.util.Log
import com.alibaba.android.arouter.BuildConfig
import com.alibaba.android.arouter.launcher.ARouter
import com.tencent.live2.V2TXLivePremier
import com.tencent.live2.V2TXLivePremier.V2TXLivePremierObserver
import com.tencent.mmkv.MMKV
import com.tencent.rtmp.TXLiveBase
import dagger.hilt.android.HiltAndroidApp


@HiltAndroidApp
class App:Application() {
    override fun onCreate() {
        super.onCreate()
        val rootDir = MMKV.initialize(this)
        println("MMKV root: $rootDir")
        ARouter.openLog()
        ARouter.openDebug()
        ARouterInit(this)

        // 腾讯直播初始化
        initTencentLive()
    }

    /**
     * ARouter的初始化
     */
    private fun ARouterInit(myApplication: App) {
        if (BuildConfig.DEBUG) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
    }

    private fun initTencentLive() {
        val licenceURL = "" // 获取到的 licence url
        val licenceKey = "" // 获取到的 licence key
        TXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey)

        V2TXLivePremier.setObserver(object : V2TXLivePremierObserver() {
            override fun onLicenceLoaded(result: Int, reason: String) {
                Log.i(TAG, "onLicenceLoaded: result:$result, reason:$reason")
            }
        })
    }
}